package com.atcumt.Thread.ProductorAndConsumer;

public class Test {

    public static void main(String[] args) {
        waitAndNotifyDemo queue = new waitAndNotifyDemo(10);
        Producer producer = new Producer(queue);

        Consumer consumer = new Consumer(queue);

        new Thread(producer).start();

        new Thread(consumer).start();
    }
}

class Producer implements Runnable {
    private waitAndNotifyDemo storage;

    public Producer(waitAndNotifyDemo storage) {
        this.storage = storage;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                storage.put();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class Consumer implements Runnable {
    private waitAndNotifyDemo storage;

    public Consumer(waitAndNotifyDemo storage) {
        this.storage = storage;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                storage.take();
            } catch (InterruptedException e) {
                e.printStackTrace();           
            }
        }
    }
}
